import * as XLSX from 'xlsx'

export default () => {
  /**
   * 读取xlsx文件
   * @param callBack 返回对wb的操作
   */
  const readxls = async (callBack: (wb: XLSX.WorkBook) => void) => {
    const files = await showOpenFilePicker()
    const file = await files[0].getFile()

    const reader = new FileReader()
    reader.onload = async function (e: any) {
      const data = e.target.result
      const wb = XLSX.read(data, { type: 'binary' })
      callBack(wb)
      // const row = XLSX.utils.sheet_to_json(wb.Sheets['关键人员库'])
      // console.log(row)
    }
    reader.readAsBinaryString(file)
  }

  return { readxls }
}
